home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / APPS / PD / EULER / PROGS / DEMO.E next >
Encoding:
Text File  |  1992-10-01  |  23.8 KB  |  932 lines

  1. .. The Demo. Starts automatically.
  2.  
  3. ""
  4. "Demo loading."
  5. ""
  6.  
  7. demodelay=180;
  8.  
  9. function delay
  10.     global demodelay;
  11.     return demodelay
  12. endfunction
  13.  
  14. function warten
  15.     wait(delay());
  16.     return 0;
  17. endfunction
  18.  
  19. function cplot(z)
  20. ## cplot(z) plots a matrix of complex values, which contains the values
  21. ## of a function at some rectangular grid.
  22.     plot(re(z),im(z)); hold on;
  23.     plot(re(z'),im(z')); hold off;
  24.     return 0;
  25. endfunction
  26.  
  27. function fisch
  28. ## plots a fish
  29.     global Pi;
  30.     t=0:3;
  31.     ph=interp(t,[0.05,0.3,0.2,1.2]);
  32.     pb=interp(t,[0.05,0.5,0.2,0.2]);
  33.     phi=Pi-linspace(0,2*Pi,20);
  34.     l=linspace(0,3,40);
  35.     psin=dup(sin(phi),length(l));
  36.     pcos=dup(cos(phi),length(l));
  37.     lh=dup(interpval(t,ph,l),length(phi))';
  38.     lb=dup(interpval(t,pb,l),length(phi))';
  39.     x=pcos*lb; z=psin*lh; y=dup(l-1.5,length(phi))';
  40.     view(2.5,1.5,0.3,0.1);
  41.     solid(x,y,z);
  42.     title("A solid fish (return)"); warten();
  43.     return 0;
  44. endfunction
  45.  
  46. function grafikdemo
  47. ## grafikdemo shows the grafik capabilities of EULER
  48.     fullwindow(); hold off;
  49.     global Pi;
  50.  
  51.     "Demo of EULER's graphics." ""
  52.     "These graphics have been programmed with a few lines."
  53.     "Study demo for more information!"
  54.     weiter();
  55.     
  56. ## Abbildungen von R nach R
  57.     t=-Pi:Pi/20:Pi;
  58.     shrinkwindow(); setplot(-Pi,Pi,-2,2);
  59.     plot(t,sin(t)); hold on;
  60.     color(2); style("."); plot(t,cos(t)); 
  61.     color(3); style("--"); plot(t,(sin(t)+cos(t))/2);
  62.     xgrid(-3:1:3,1); ygrid(-1:1,1);
  63.     title("2D plots (return)");
  64.     color(1); style(""); fullwindow(); hold off;
  65.     warten();
  66.     
  67. ## Abbildungen von R nach R^2 in vier Fenstern
  68.     t=-Pi:Pi/50:Pi;
  69.     window(10,textheight()*1.5,490,490);
  70.     plot(sin(3*t)/3+cos(t),sin(3*t)/3+sin(t)); hold on;
  71.     title("Parametric curves (return)"); 
  72.     window(510,textheight()*1.5,1010,490);
  73.     plot(sin(2*t)/3+cos(t),sin(2*t)/3+sin(t));
  74.     window(10,510,490,1010);
  75.     plot(sin(2*t),sin(3*t));
  76.     window(510,510,1010,1010);
  77.     t=t+2*Pi;
  78.     plot(cos(t)*log(t),sin(t)*log(t));
  79.     hold off;
  80.     warten();
  81.     
  82. ## x^2+y^3 als mesh und contour.
  83.     fullwindow();
  84.     t=-1:0.1:1; t=t*Pi;
  85.     {x,y}=field(t,t);
  86.     mesh(x*x+y*y*y); title("x^2+y^3 (return)"); warten();
  87.     contour(x*x+y*y*y,-12:2:12);
  88.     title("Contour plot of this function (return)"); warten();
  89.     
  90. ## e^-r cos(r) als Drahtmodell.
  91.     r=x*x+y*y; f=exp(-r)*cos(r);
  92.     view(2,1,0,0.5); ## [ Abstand, Zoom, Winkel rechts, Winkel hoch ]
  93.     wire(x/Pi,y/Pi,f);
  94.     title("Wire frame model (return)"); warten();
  95.  
  96. ## Der Torus als solides Modell.
  97.     fisch();
  98.     view(2,1,0.2,0.3);
  99.  
  100. ## Eine complexe Abbildung w=z^1.3
  101.     setplot(-1, 2, -0.5, 1.5);
  102.     t=0:0.1:1; z=dup(t,length(t)); z=z+1i*z';
  103.     color(1); style("."); cplot(z); hold on;
  104.     color(2); style(""); cplot(z^1.3); color(1);
  105.     xgrid(0); ygrid(0);
  106.     title("Complex numbers w=z^1.3"); hold off;
  107.     warten();
  108.     
  109.     "End"
  110.     return 0
  111. endfunction
  112.  
  113. function weiter
  114.     "" "<< Press return to continue >>" warten(); "",
  115.     return 120;
  116. endfunction
  117.  
  118. function normaldemo
  119. ## Einführung in EULER
  120.     global Pi; pi=Pi;
  121.     
  122.     "Hint for window versions:"
  123.     ""
  124.     "Use the scrollbars to see the complete text"
  125.     "(or Shift+Cursorup or PageUp on some systems),"
  126.     "if the text disappeared."
  127.     weiter();
  128.  
  129.     "                             Wellcome at EULER" 
  130.     ""
  131.     "EULER has been designed to ease numerical computation."
  132.     "Most of the time one has a tiny problem, to tiny to use a compiler"
  133.     "language."
  134.     ""
  135.     "Besides, one may want to play with intermediate results, see a"
  136.     "graphical representation, or simply have readily available"
  137.     "numerical functions."
  138.     "" 
  139.     "All this can be done with EULER."
  140.     "It is like using a numerical laboratory."
  141.     weiter();
  142.     
  143.     "But EULER is not a symbolic algebra program. It uses numbers with"
  144.     "finite accuracy as supplied by the C compiler used. It is therefore"
  145.     "faster than a symbolic program, like MATHEMATICA."
  146.     ""
  147.     "All commands are entered by the keyboard. Old commands can be"
  148.     "recalled with cursor up or down. ESC interrupts a computation,"
  149.     "and HELP shows the graphics screen."
  150.     weiter();
  151.     
  152. ## Eingabe von Matrizen
  153.     "With EULER one can enter matrices like this:" ""
  154.     ">x=[5,6,7]" x=[5,6,7], 
  155.     ">A=[1,2,3;5,6,7;8,9,0]" A=[1 2 3;5 6 7;8 9 0],
  156.     "The comma may be omitted."
  157.     "These matrices are stored on the variables x and A."
  158.     weiter();
  159.     
  160.     "All computing is done element for element."
  161.     ">x*x" x*x,
  162.     ">A+A" A+A,
  163.     weiter();
  164.     
  165. ## Complexe Zahlen.
  166.     "Complex numbers and complex computations."
  167.     ">1+2i", 1+2i,
  168.     ">c=[1i 3 4+5i]", c=[1i 3 4+5i],
  169.     "" ">1i*1i", 1i*1i,
  170.     ">exp(1i*pi/2)", exp(1i*pi/2),
  171.     weiter();
  172.     
  173. ## Matrixprodukt.
  174.     "The dot multiplies two matrices."
  175.     ">A.x'" A.x'
  176.     "Note, that x had to be transposed!"
  177.     "" ">x", x,
  178.     weiter();
  179.     
  180.     "" ">x'", x',
  181.     "" ">x'.x" x'.x,
  182.     weiter();
  183.     
  184. ## :
  185.     "Generating vectors:"
  186.     ">1:10", 1:10,
  187.     ">-1:0.3:1", -1:0.3:1,
  188.     weiter();
  189.     
  190.     ">[1 2 3]|[4 5]", [1 2 3]|[4 5],
  191.     ">[1 2 3]_[4 5 8]", [1 2 3]_[4 5 8],
  192.     ">dup([1 2 3],4)", dup([1 2 3],4),
  193.     weiter();
  194.     
  195. ## Funktionen.
  196.     "Also all functions are applied to all elements of a matrix."
  197.     "" ">sqrt([1,2,3,4])" sqrt([1,2,3,4]),
  198.     ""
  199.     "There are all the numerical functions."
  200.     "See an overview with >list."
  201.     weiter();
  202.     
  203.     "It is easy to generate a table for a function, and with
  204.     "the table, one can plot the function."
  205.     "" ">t=0:pi/50:2*pi; s=sin(t); xplot(t,s);"
  206.     t=0:pi/50:2*pi; s=sin(t);
  207.     "plots the sine function in [0,2*Pi]",
  208.     weiter();
  209.     shrinkwindow(); xplot(t,s); title("Please press return!");
  210.     fullwindow();
  211.     warten();
  212.  
  213. ## Untermatrizen.
  214.     "Submatrices:" ""
  215.     ">x=[11 12 13;21 22 23; 31 32 33]"
  216.     x=[11 12 13;21 22 23; 31 32 33],
  217.     ">x(1)" x(1),
  218.     "One can write x[...] or x(...).",
  219.     weiter();
  220.     
  221.     ">x[1:2,2]", x[1:2,2],
  222.     ">x[2:6,2:6]" x[2:6,2:6],
  223.     ">x[:,3]", x[:,3],
  224.     ">x[1,[2 2 1 3]]", x[1,[2 2 1 3]],
  225.     weiter();
  226.     
  227. ## Numerische Integration.
  228.     "An example:" ""
  229.     ">sum(sin((1:100)/100))" sum(sin((1:100)/100)),
  230.     "" 
  231.     "Let us integrate the sine in [0,pi] using the simpson method (but"
  232.     "not the builtin functions). The exact value is 2."
  233.     ">t=0:pi/50:pi; n=length(t);", 
  234.     t=0:pi/50:pi; n=length(t);
  235.     ">f=2*mod((1:n)+1,2)+2; f[1]=1; f[n]=1;",
  236.     f=2*mod((1:n)+1,2)+2; f[1]=1; f[n]=1;
  237.     ">result=sum(sin(t)*f)/3*(t[2]-t[1])", 
  238.     longformat(); result=sum(sin(t)*f)/3*(t[2]-t[1]),
  239.     shortformat();
  240.     "" "; surpresses output of intermediate results."
  241.     weiter();
  242.     
  243.     "By the way:"
  244.     ">f[1:5]", f[1:5],
  245.     ">f[n-4:n]", f[n-4:n],
  246.     weiter();
  247.     
  248. ## Gleichungssysteme.
  249.     "Solve linear systems:"
  250.     "" ">a=hilb(10); b=a.dup(1,10); a\b" ""
  251.     longformat(); a=hilb(10); b=a.dup(1,10); a\b, shortformat();
  252.     ""
  253.     "The inaccuracy is unavoidable for the Hilbert matrix." 
  254.     weiter();
  255.     
  256. ## Kurvendiskussion.
  257.     "A discussion" ""
  258.     "The function:"
  259.     ">x=1:0.02:10; y=log(x)/x;"
  260.     x=1:0.02:10; y=log(x)/x;
  261.     "The function looks like this (press any key)"
  262.     warten();
  263.     shrinkwindow();
  264.     xplot(x,y); ygrid(0); title("(return)"); warten();
  265.     "" "The maximal value is: " ">m=max(y)",
  266.     m=max(y),
  267.     "" "it is obtained in" ">x(nonzeros(y>=m))",
  268.     x(nonzeros(y>=m)),
  269.     "" "The first derivative (numerically)"
  270.     ">n=length(x); a=(y[2:n]-y[1:n-1])/(x[2:n]-x[1:n-1]);"
  271.     n=length(x); a=(y[2:n]-y[1:n-1])/(x[2:n]-x[1:n-1]);
  272.     xplot((x[2:n]+x[1:n-1])/2,a); ygrid(0); title ("(return)");
  273.     fullwindow();
  274.     warten();
  275.     
  276.     weiter();
  277.     return 0
  278. endfunction
  279.  
  280. .. *** Approximations - Demo ***
  281.  
  282. function apprdemo
  283.     global Pi; pi=Pi;
  284.     
  285. ## L_2-Approximation.
  286.     "Some approximation problems."
  287.     "" "First the x-values and the function values are computed:"
  288.     "" ">x=0:0.02:1; y=sqrt(x);", x=0:0.02:1; y=sqrt(x);
  289.     "" "Then the matrix of polynomial values:"
  290.     "" ">n=length(x); p=polyfit(x,y,5),",
  291.     n=length(x); p=polyfit(x,y,5),
  292.     "" 
  293.     ">plot(x,y); hold on; color(3); "| ..
  294.     "plot(x,polyval(p,x)); color(1); hold off;"
  295.     weiter();
  296.     plot(x,y); hold on; color(3);
  297.     plot(x,polyval(p,x)); color(1); hold off;
  298.     title("sqrt(x) and its best L_2-approximation (return)"); warten();
  299.     plot(x,y-polyval(p,x)); ygrid(0); title("The error (return)"); warten();
  300.     "The maximal error in this interval is"
  301.     "" ">max(abs(y-polyval(p,x)))", max(abs(y-polyval(p,x))),
  302.     weiter();
  303.     
  304. ## Interpolation.
  305.     "Interpolation:" ""
  306.     ">t=equspace(0,1,5); s=sin(t); d=interp(t,s);",
  307.     t=equispace(0,1,5); s=sin(t); d=interp(t,s);
  308.     "" ">x=0:0.01:1; max(x,abs(interpval(t,d,x)-sin(x)))",
  309.     x=0:0.01:1; max(abs(interpval(t,d,x)-sin(x))),
  310.     "" ">plot(x,interpval(t,d,x)-sin(x)); ygrid(0); ",
  311.     weiter();
  312.     plot(x,interpval(t,d,x)-sin(x)); ygrid(0);
  313.     title("Interpolation error (return)"); warten();    
  314.     
  315. ## Fourierreihe.
  316.     "Discrete Fourier series:"
  317.     ""
  318.     ">n=64; t=0:pi/n:2*pi-pi/n; s=(t<pi); w=fft(s);"
  319.     n=64; t=0:pi/n:2*pi-pi/n; s=(t<pi); w=fft(s);
  320.     ">w[12:2*n-10]=zeros(1, 2*n-21); s1=re(ifft(w));"
  321.     w[12:2*n-10]=zeros(1, 2*n-21); s1=re(ifft(w));
  322.     weiter();
  323.     setplot(0, 2*pi, -0.5, 1.5);
  324.     plot(t,s); hold on;
  325.     color(3); plot(t,s1);
  326.     color(1);
  327.     hold off;
  328.     title("(return)"); warten();
  329.  
  330. ## Fourieranalyse.
  331.     "Fourier analysis"
  332.     ""
  333.     "The signal:"
  334.     ">t=(0:127)*2*pi/128; x=sin(10*t)+2*cos(15*t);"
  335.     t=(0:127)*2*pi/128; x=sin(10*t)+2*cos(15*t);
  336.     "" "Add some noise:"
  337.     ">y=x+normal(size(x));"
  338.     y=x+normal(size(x));
  339.     setplot(0,2*pi,-5, 5); 
  340.     plot(t,x); hold on;
  341.     color(3); plot(t,y); color(1);
  342.     title("Signal und signal with noise (return)"); warten();
  343.     hold off;
  344.     ""
  345.     "Now the Fourier analysis:" 
  346.     ">c=fft(y); p=abs(c)^2;"
  347.     c=fft(y); p=abs(c);
  348.     plot(0:64,p(1:65)); xgrid([10,15]);
  349.     title("Spectral analysis (return)"); warten();
  350.     weiter();
  351.     
  352.     return 0;
  353.  
  354. endfunction
  355.  
  356. .. *** Statistik - Demo ***
  357.  
  358. function statdemo
  359. ## Statistikdemo.
  360.     global Pi; pi=Pi;
  361.     
  362. ## t-Test.
  363.     "Statistics :" ""
  364.     "Let us generate 10 simulated measurements:"
  365.     "" ">x=1000+5*normal(1, 10)",
  366.     x=1000+5*normal(1, 10),
  367.     "" "Mean value:" ">m=sum(x)/10", m=sum(x/10),
  368.     "" "Standart deviation:", ">d=sqrt(sum((x-m)^2)/9),"
  369.     d=sqrt(sum((x-m)^2)/9),
  370.     weiter();
  371.     "" "A 95-% confidence interval for the mean value:"
  372.     "" ">t=invtdis(0.975,9)*d/3; [m-t,m+t]",
  373.     t=invtdis(0.975,9)*d/3; [m-t,m+t],
  374.     weiter();
  375.     
  376. ## xhi^2
  377.     "Statistical evaluation of dice throws."
  378.     ""
  379.     ">x=random(1, 600); t=count(x*6,6)'",
  380.     x=random(1, 600); t=count(x*6,6),
  381.     "Compute chi^2" ">chi=sum((t-100)^2/100),"
  382.     chi=sum((t-100)^2/100),
  383.     "We decide that the dice is unbiased, since"
  384.     ">1-chidis(chi,5)" 1-chidis(chi,5),
  385.     weiter();
  386.     "Now we simulate a biased dice:"
  387.     ">x=(x<0.95)*x; t=count(x*6,6), chi=sum((t-100)^2/100);"
  388.     x=(x<0.95)*x; t=count(x*6,6), chi=sum((t-100)^2/100);
  389.     "Error probability:"
  390.     ">1-chidis(chi,5)"
  391.     1-chidis(chi,5),
  392.     weiter();
  393.     
  394. ## Binomialverteilung
  395.     "The binomial distribution:"
  396.     "" ">n=20; t=0:n; p=0.4; b=p^t*(1-p)^(n-t)*bin(n,t);"
  397.     ">color(3); mark(t,b); color(1);"
  398.     n=20; t=0:n; p=0.4; b=p^t*(1-p)^(n-t)*bin(n,t);
  399.     "" ">d=sqrt(n*p*(1-p));"
  400.     ">s=exp(-((t-20*p)/d)^2/2)/(d*sqrt(2*pi));"
  401.     ">hold on; plot(t,s); hold off;"
  402.     weiter();    
  403.     color(3); mark(t,b); color(1);
  404.     d=sqrt(n*p*(1-p));
  405.     s=exp(-((t-20*p)/d)^2/2)/(d*sqrt(2*pi));
  406.     hold on; plot(t,s);
  407.     title("Binomial and normal distribution (press return)"); hold off;
  408.     warten();
  409.  
  410. ## Mehrfeldertest
  411.     "chi^2 test:"
  412.     ""
  413.     "Given the matrix:"
  414.     ">a"
  415.     format(5,0);
  416.     a=[23,37,43,52,67,74;45,25,53,40,60,83];
  417.     a, shortformat();
  418.     ""
  419.     "The matrix of expected values:"
  420.     ">{k,l}=field(sum(a')',sum(a)'); s=totalsum(a); b=(k*l)/s;"
  421.     {k,l}=field(sum(a')',sum(a)'); s=totalsum(a); b=(k*l)/s;
  422.     weiter();
  423.     "Compute chi^2:"
  424.     ">chi=totalsum((a-b)^2/b); 1-chidis(chi,5),"
  425.     chi=totalsum((a-b)^2/b); 1-chidis(chi,5),
  426.     ""
  427.     "That means we decide that the columns do not depend of the rows."
  428.     weiter();
  429.  
  430. ## Regression.
  431.     "Regression analysis:" ""
  432.     "A linear function with errors: "
  433.     "" ">t=0:0.2:5; s=2*t+3+0.2*normal(size(t));",
  434.     t=0:0.2:5; s=2*t+3+0.2*normal(size(t));
  435.     ">p=polyfit(t,s,1),",
  436.     p=polyfit(t,s,1),
  437.     ">color(3); mark(t,s); hold on; color(1); plot(t,polyval(p,t)); hold off;"
  438.     weiter();
  439.     color(3); mark(t,s); hold on; color(1); plot(t,polyval(p,t)); hold off;
  440.     title("The best fit (press return)"); warten();
  441.     
  442.     return 0;
  443. endfunction
  444.  
  445. function fibo(n)
  446. ## fibo(n) liefert einen Vektor mit den ersten n Finonaccizahlen.
  447.     if (n<3) return [1 1]; endif;
  448.     f=ones(1, n);
  449.     for i=3 to n; f[i]=f[i-1]+f[i-2]; end;
  450.     return f
  451. endfunction
  452.  
  453. function itertest(x)
  454. ## itertest(x) konvergiert gegen sqrt(2).
  455.     repeat;
  456.         x=(x+2/x)/2; x,
  457.         if x*x~=2; break; endif;
  458.     end;
  459.     return x;
  460. endfunction
  461.     
  462. function multitest
  463.     return {arg1,arg1*arg1}
  464. endfunction
  465.  
  466. function hut (x,y)
  467.     si=size(x,y); z=zeros(si);
  468.     loop 1 to prod(si);
  469.         r=x{#}^2+y{#}^2;
  470.         if r<1; z{#}=exp(-1/(1-r)); endif;
  471.     end;
  472.     return exp(1)*z
  473. endfunction
  474.         
  475. function udfdemo
  476.     "EULER is programmable.",
  477.     "" "As an example we list a function, which computes the first n"
  478.     "fibonacci numbers when called with fibo(n):"
  479.     weiter();
  480.     ">type fibo",
  481.     type fibo;
  482.     ">fibo(5)", fibo(5),
  483.     weiter();
  484.     "As you can see, a function starts with" 
  485.     ">function name" 
  486.     "and ends with"
  487.     ">end"|"function" 
  488.     "Every function must have a return statement, which stops it."
  489.     weiter();
  490.     "Arguments are named arg1, arg2, arg3, ...,"
  491.     "unless they are given names in the function header."
  492.     "argn() gives the number of arguments. All variables are local and"
  493.     "cease to exist after function execution is finished."
  494.     "But the command" ">global name"
  495.     "allows acces of a global variable."
  496.     weiter();
  497.     
  498.     "There are:" 
  499.     ""
  500.     "Conditionals:"
  501.     ">if condition; ... { else; ... } endif;"
  502.     ""
  503.     "The condition can be any expression, especially a test like < > etc."
  504.     "Logical connections are made with || (or) and && (and)."
  505.     "!condition means: not condition."
  506.     weiter();
  507.     "Repetitive statements:"
  508.     ">for variable=start to end { step value }; ... end;"
  509.     ">loop start to end; ... end;"
  510.     ">repeat; ... end;"
  511.     weiter();
  512.     "In loop's the index can be accessed with index() or #."
  513.     "All these statements can be left with a break; or return ...;"
  514.     weiter();
  515.     
  516.     "" "Example:"
  517.     ""
  518.     type itertest
  519.     ""
  520.     ">longformat(); itertest(1.5), shortformat();", 
  521.     longformat(); itertest(1.5), shortformat();
  522.     weiter();
  523.  
  524.     "A function can return multiple values and these values can be"
  525.     "assigned to several variables."
  526.     ""
  527.     "Syntax:"
  528.     ">return {variable,variable,...}"
  529.     "The brackets { and } are part of the syntax here."
  530.     "Then the multiple assignment looks like:"
  531.     ">{a,b}=test(parameter)"
  532.     weiter();
  533.     "An example:"
  534.     ""
  535.     type multitest
  536.     ""
  537.     "{a,b}=multitest(2); a, b,", {a,b}=multitest(2); a, b,
  538.     weiter();
  539.     
  540.     "Comments start with #"|"#. Comments are not listet with type."
  541.     "If the first lines of a functions start with #"|"#,"
  542.     "they are considered help text. With help this text can be read."
  543.     ""
  544.     ">help field" "", help field,
  545.     weiter();
  546.  
  547.     "Since all EULER functions work for vector and matrix input,"
  548.     "user defined functions should be written the same way."
  549.     "Most of the time, this is automatic. But sometimes a function"
  550.     "uses a complicate algorithm or cases. Then there is the {} indexing"
  551.     "which treats the matrix like a vector."
  552.     weiter();
  553.     ">type hut", type hut
  554.     ""
  555.     v=view(5,2,0,0.4);
  556.     ">{x,y}=field(-1.2:0.2:1.2,-1.2:0.2:1.2); framedsolid(x,y,hut(x,y));",
  557.     {x,y}=field(-1.2:0.2:1.2,-1.2:0.2:1.2); 
  558.     framedsolid(x,y,hut(x,y)); title("(return)");
  559.     view(v);
  560.     wait(delay());
  561.     ""
  562.     shrinkwindow();
  563.     ">x=-2:0.05:2; xplot(x,hut(x,0));",
  564.     x=-2:0.05:2; xplot(x,hut(x,0)); title("(return)"); wait(delay());
  565.     fullwindow();
  566.     weiter();
  567.  
  568.     "Functions should be written with an external editor."
  569.     "You can start an editor from within EULER, like any other program."
  570.     "(Not for XWindow version)"
  571.     "" ">exec string",
  572.     weiter();
  573.     "The string must be in double quotes or must be a variable, which"
  574.     "has been assigned a string. It consists of the program name and"
  575.     "paramters to be passed to the program; e.g.,"
  576.     "" ">exec "|char(34)|"editor.prg testfile"|char(34),
  577.     "" "or"
  578.     "" "a="|char(34)|"editor.prg test"|char(34)|"; a",
  579.     a="editor.prg test"; a,
  580.     "" ">exec a"
  581.     "(Calls Editor.prg)"
  582.     weiter();
  583.  
  584.     "You can echo output to a file"
  585.     ""
  586.     ">dump filename"
  587.     "" 
  588.     "Again, filename must be string expression."
  589.     weiter();
  590.     "With"
  591.     ">dump"
  592.     "echoing is stopped and the file closed."
  593.     ""
  594.     "Dumps are always appended to the file."
  595.     "With"
  596.     ">remove filename"
  597.     "the file is removed (killed)."
  598.     ""
  599.     "By the way:"
  600.     ">forget f; clear a;"
  601.     "removes a function and the variable a."
  602.     weiter();
  603.     
  604.     return 0
  605. endfunction
  606.  
  607. function f(x)
  608.     return exp(x)-1.5;
  609. endfunction
  610.  
  611. function dgl(x,y)
  612.     return -2*x*y;
  613. endfunction
  614.  
  615. function specialdemo
  616.  
  617. ## Simpson
  618.     "Simpson integral : ",
  619.     ""
  620.     ">type f", type f;
  621.     ""
  622.     ">t=simpson("|char(34)|"f"|char(34)|",0,1)", t=simpson("f",0,1),
  623.     ""
  624.     "The error : "
  625.     ""
  626.     "t-(exp(1)-2.5)," t-(exp(1)-2.5),
  627.     weiter();
  628.  
  629. ## Bisektion
  630.     "Solutions of an equation : "
  631.     ""
  632.     ">type f", type f;
  633.     ""
  634.     ">t=bisect("|char(34)|"f"|char(34)|",0,1),", t=bisect("f",0,1),
  635.     ""
  636.     "Error : "
  637.     ""
  638.     ">t-log(1.5)", t-log(1.5),
  639.     weiter();
  640.     
  641. ## Differentialgleichung
  642.     "Differential equations : "
  643.     ""
  644.     ">type dgl", type dgl;
  645.     ""
  646.     ">t=0:0.05:2; s=heun("|char(34)|"dgl"|char(34)|",t,1); plot(t,s);"
  647.     t=0:0.05:2; s=heun("dgl",t,1); plot(t,s); title("(return)"); warten();
  648.     ""
  649.     "Maximal error : "
  650.     ""
  651.     ">max(abs(s-exp(-t^2)))", max(abs(s-exp(-t^2))),
  652.     weiter();    
  653.  
  654. ## Eigenwerte :
  655.     "Eigenvalues and eigenvectors : " ""
  656.     "Given the matrix"
  657.     ">A=[0,1;1,1]", A=[0,1;1,1],
  658.     ""
  659.     "We compute the eigenvalues and eigenvectors of A."
  660.     ">{l,V}=eigen(A); l=re(l),"
  661.     {l,V}=eigen(A); l=re(l),"
  662.     ">V=re(V),"
  663.     V=re(V), 
  664.     weiter();
  665.     "Then V'.D.V=A."
  666.     ""
  667.     ">D=diag(size(A),0,l); V'.D.V,"
  668.     D=diag(size(A),0,l); V'.D.V,
  669.     weiter();
  670.  
  671.     return 0;    
  672. endfunction
  673.  
  674. function taste
  675.     "<< Please press return >>", "",
  676.     return wait(delay());
  677. endfunction
  678.  
  679. function grafiktutor
  680. ## Erklärt die Grafikfunktionen
  681.     hold off;
  682.     global Pi;
  683.     "Explanation of some grafics functions."
  684.     ""
  685.     "First we compute a vector of x-values."
  686.     ">x=-1:0.02:1;" x=-1:0.02:1;
  687.     "Then we compute the function at these points."
  688.     ">y=sin(4*Pi*x)*exp(-x*x);" y=sin(4*Pi*x)*exp(-x*x);
  689.     "Finally we can plot the function."
  690.     ">plot(x,y);"
  691.     taste();
  692.     plot(x,y); wait(delay);
  693.     "The plot can be given a title."
  694.     ">title("|char(34)|"sin(4*Pi*x)*exp(-x*x),(return)"| ..
  695.         char(34)|");"
  696.     taste();
  697.     title("sin(4*Pi*x)*exp(-x*x),(return)"); wait(delay());
  698.     "For x- and y-grids, we use the following commands."
  699.     ">xgrid(-0.5:0.5:0.5); ygrid(-1:0.5:1);"
  700.     taste();
  701.     xgrid(-0.5:0.5:0.5); ygrid(-1:0.5:1); wait(delay);
  702.     "To draw another plot above it, we use the hold command.",
  703.     ">hold on; plot(x,cos(4*Pi*x)*exp(-x*x)); hold off;"
  704.     taste();
  705.     hold on; plot(x,cos(4*Pi*x)*exp(-x*x)); hold off; wait(delay);
  706.  
  707.     "One can plot several curves wth a single plot command."
  708.     "",
  709.     "This time, the grid is to have labels."
  710.     ">shrinkwindow();" shrinkwindow();
  711.     "", ">{x,n}=field(linspace(-1,1,50),1:5); T=cos(n*acos(x));"
  712.     {x,n}=field(linspace(-1,1,50),1:5); T=cos(n*acos(x));
  713.     "This way we computed 5 rows of 5 functions cos(n*acos(x))."
  714.     "", "First we set the plot region manually.",
  715.     ">setplot(-1.5,1.5,-1.5,1.5);"
  716.     "The we plot all functions."
  717.     ">plot(x,T); xgrid(-2:2,1); ygrid(-2:2,1); wait(delay); hold off;"
  718.     setplot(-1.5,1.5,-1.5,1.5);
  719.     plot(x,T); xgrid(-2:2,1); ygrid(-2:2,1); wait(delay); hold off;
  720.     "One can also mark a point on the screen with the mouse."
  721.     ">title("|char(34)|"Click the left mouse button."|char(34)| ..
  722.     "); c=mouse(); c,"
  723.     taste();
  724.     if delay>30;
  725.         title("Click the left mouse button."); c=mouse(); c,
  726.         "These are the coordinates, you choose."
  727.         taste();
  728.     endif;
  729.     
  730.     "Now a function with a singularity."
  731.     ""
  732.     ">t=-1:0.01:1; setplot(-1,1,-10,10);"
  733.     t=-1:0.01:1; setplot(-1,1,-10,10);
  734.     ">xplot(t,1/t); hold on; xplot(t,1/t^2); hold off;"
  735.     xplot(t,1/t); hold on; plot(t,1/t^2); hold off;
  736.     ""
  737.     taste();
  738.     title("1/t and 1/t^2 (return)"); wait(delay());
  739.  
  740.     "Functions of two variables :"
  741.     ""
  742.     "First we compute a grid of x- and y-coordinates."
  743.     ">{x,y}=field(-1:0.1:1,-1:0.1:1);"
  744.     {x,y}=field(-1:0.1:1,-1:0.1:1);
  745.     "", "Then we compute the function values at these grid points and"
  746.     "draw them."
  747.     ">z=x*x+x*y-y*y; mesh(z);"
  748.     taste();
  749.     z=x*x+x*y-y*y; fullwindow(); mesh(z); wait(delay());
  750.     "The contour level lines of these function we can inspect with"
  751.     ">contour(z,-3:0.5:3);"
  752.     taste();
  753.     contour(z,-3:0.5:3); wait(delay);
  754.     "A perspective view of the same surface."
  755.     ">view(2.5,1,1,0.5); solid(x,y,z);"
  756.     taste();
  757.     view(2.5,1,1,0.5); solid(x,y,z); wait(delay);
  758.     "A wire fram model."
  759.     ">wire(x,y,z);"
  760.     taste();
  761.     wire(x,y,z); wait(delay);
  762.     
  763.     return 0
  764. endfunction
  765.  
  766. function abspann
  767.     "As I think, this demo has given you a good impression. So"
  768.     "EULER is well suited for many tasks in applied mathematics, as"
  769.     "well as for viewing functions of one or two variables."
  770.     ""
  771.     "The author wishes you succes with mathematics and EULER!"
  772.     return 0
  773. endfunction
  774.  
  775. function torus
  776. ## some torus type bodies.
  777.     view([4,1,0,0.6]);
  778.     global Pi;
  779.     x=linspace(0,2*Pi,40);
  780.     y=linspace(0,2*Pi,20);
  781.     cosphi=dup(cos(x),length(y));
  782.     sinphi=dup(sin(x),length(y));
  783.     cospsi=dup(cos(y'),length(x));
  784.     sinpsi=dup(sin(y'),length(x));
  785. ## faster than {phi,psi}=field(x,y); cosphi=cos(phi); ...
  786.  
  787. ## a torus with a thick and a thin side.    
  788.     factor=1.5+cospsi*(cosphi/2+0.6);
  789.     X=cosphi*factor;
  790.     Y=sinphi*factor;
  791.     Z=sinpsi*(cosphi/2+0.6);
  792.     solid(X,Y,Z); title("(Return)"); wait(delay);
  793.     
  794. ## a deformed torus
  795.     factor=1.5+cospsi;
  796.     X=cosphi*factor;
  797.     Y=sinphi*factor;
  798.     Z=sinpsi+dup(cos(2*x),length(y));
  799.     solid(X,Y,Z); title("(Return)"); wait(delay);
  800.     
  801. ## the Moebius band
  802.     t=dup(linspace(-1,1,20)',length(x));    
  803.     x=linspace(0,Pi,40);
  804.     cosphi1=dup(cos(x),length(y));
  805.     sinphi1=dup(sin(x),length(y));
  806.     factor=2+cosphi1*t;
  807.     X=cosphi*factor;
  808.     Y=sinphi*factor;
  809.     Z=sinphi1*t;
  810.     solid(X,Y,Z); title("Return"); wait(delay);
  811.  
  812.     return 0;
  813. endfunction
  814.  
  815. function tube
  816. ## some tube like bodies.
  817.     view([3,1,0,0.1]);
  818.     global Pi;
  819.     x=linspace(0,2*Pi,40);
  820.  
  821. ## a atomic modell or so.
  822.     y=0.1+(sin(linspace(0,Pi,15))| ..
  823.         1.5*sin(linspace(0,Pi,10))|sin(linspace(0,Pi,15)));
  824.     cosphi=dup(cos(x),length(y));
  825.     sinphi=dup(sin(x),length(y));
  826.     f=dup(y',length(x));
  827.     
  828.     solid(f*cosphi,f*sinphi,dup(linspace(-2,2,length(y)-1)',length(x)));
  829.     title("(Return)");
  830.     wait(delay); 
  831.  
  832. ## a black hole
  833.     t=linspace(0,1,20);
  834.     cosphi=dup(cos(x),length(t));
  835.     sinphi=dup(sin(x),length(t));
  836.     f=dup((t*t+0.2)',length(x));
  837.     view([3,1.5,0,0.7]);
  838.     solid(f*cosphi,f*sinphi,dup(t'*2-1,length(x)));
  839.     title("(Return)"); wait(delay);
  840.  
  841.     return 0;
  842. endfunction
  843.  
  844. function minimal (r,phi)
  845.     R=dup(r',length(phi));
  846.     X=R*dup(cos(phi),length(r))+R*R/2*dup(cos(2*phi),length(r));
  847.     Y=-R*dup(sin(phi),length(r))-R*R/2*dup(sin(2*phi),length(r));
  848.     Z=4/3*dup((r^1.5)',length(phi))*dup(cos(1.5*phi),length(r))-1;
  849.     view(9,1,-1.5,0.2);
  850.     solid(X,Y,Z);
  851.     title("A minmal surface (Return)");
  852.     wait(delay);
  853.     return 0;
  854. endfunction
  855.  
  856. function spiral
  857.     {r,a}=field(0:0.1:1,0:pi()/8:6*pi());
  858.     z=a/8;
  859.     x=r*cos(a)*(1-a/20);
  860.     y=r*sin(a)*(1-a/20);
  861.     z=z-1.5;
  862.     view(4,1.5,0.5,0.3);
  863.     framedsolid(x,y,z); title("(Return)"); wait(delay);
  864.     return 0;
  865. endfunction
  866.  
  867. function rings
  868.     rr=0.2;
  869.     t=linspace(0,2*pi,10);
  870.     s=linspace(0,2*pi,41); n=length(s);
  871.     r=dup(1+cos(t)*rr,n)'; m=length(t);
  872.     x=dup(cos(s),m)*r; y=dup(sin(s),m)*r;
  873.     z=dup(sin(t)*rr,n)';
  874.     view([4,1.5,0.3,0.3]);
  875.     X=x_(x+1.3)_(x-1.3);
  876.     Y=y_-z_-z;
  877.     Z=z_y_y;
  878.     solid(X,Y,Z,[m,2*m]);
  879.     return 0;
  880. endfunction
  881.  
  882. function startdemo
  883.     {x,y}=field(-1:0.1:1,-1:0.1:1);
  884.     z=x*x+y*y;
  885.     mesh(z); title("(Return)"); wait(delay);
  886.     return 0;
  887. endfunction
  888.  
  889. function demo3d
  890.     startdemo();
  891.     torus();
  892.     tube();
  893.     minimal(0.1:0.1:2.5,0:pi()/20:2*pi());
  894.     spiral();
  895.     rings();
  896.     return 0;
  897. endfunction
  898.  
  899. function demos
  900.     normaldemo();
  901.     grafikdemo();
  902.     apprdemo();
  903.     statdemo();
  904.     udfdemo();
  905.     specialdemo();
  906.     grafiktutor();
  907.     demo3d();
  908.     return 0;
  909. endfunction;
  910.  
  911. function demo (del)
  912.     global demodelay;
  913.     if argn==1;
  914.         demodelay=del;
  915.     endif;
  916.     repeat;
  917.     shortformat(); style(""); fullwindow(); color(1); hold off;
  918.     demos();
  919.     abspann();
  920.     weiter();
  921.     end;
  922.     return 0
  923. endfunction
  924.  
  925. ""
  926. type demos
  927. ""
  928. "Use one of the above, or type demo() or demo(10)."
  929.  
  930. "<< Demo will start after 10 seconds. Press Esc to stop it. >>"
  931. wait(10);
  932. demo();